<template>
  <div>
    <el-dialog
      :title=title[type]
      :visible.sync="isshow"
      width="500px"
    >
      <el-input v-model="surveyName" :placeholder=placeholder[type]></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="confirm"
        >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  addQuestion
} from '@/api/questions'
import {
  confirmQuestion
} from '@/api/questions/updatequestion'

export default {
  name: 'MixedStateAdminSurveyName',
  props: {
    //1:新增问卷  2:复制问卷
    type: {
      type: [String, Number],
      default: '1'
    }

  },
  data() {
    return {
      id: '',
      surveyName: '',
      placeholder: {
        1: '请输入新增问卷标题',
        2: '请输入复制后的问卷标题'
      },
      title: {
        1: '新增问卷',
        2: '复制问卷'
      },
      isshow: false
    }
  },

  mounted() {
  },

  methods: {
    show() {
      this.surveyName = ''
      this.isshow = true
    },
    confirm() {
      if (!this.surveyName) {
        this.$modal.msgWarning('请填写问卷标题')
        return
      }
      //type==2 说明是复制文卷
      if (this.type == 2) {
        this.$emit('copySurvey', this.surveyName)
      } else {
        addQuestion().then(res => {
          this.id = res.surveyId
          confirmQuestion({ id: this.id, surveyName: this.surveyName }).then(() => {
            this.isshow = false
            this.$router.push({
              path: '/question/addQuestion',
              query: {
                id: this.id
              }
            })
          })
        })
      }
    },
    close() {
      this.isshow = false
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
